package com.example.fyptest3;

import java.io.File;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
    private Context mContext;
    File f;        
	File[] file;
	Bitmap bm = null;
	
    public ImageAdapter(Context c, String d) {
        mContext = c;
        f = new File(d);
        file = f.listFiles();
    }

    public int getCount() {
        return file.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }


    
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		 ImageView imageView;
	        if (convertView == null) {  // if it's not recycled, initialize some attributes
	            imageView = new ImageView(mContext);
	            imageView.setLayoutParams(new GridView.LayoutParams(200, 200));
	            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
	            imageView.setPadding(2, 2, 2, 2);
	        } else {
	            imageView = (ImageView) convertView;
	        }
	        
			bm = ImageDecode.staticDecodeFile(file[position]);
			
			imageView.setImageBitmap(bm);
			
	        return imageView;
	}
}
